package com.eatme.web.security.authentication.phonecode.service.impl;

import com.eatme.web.security.authentication.dao.SecurityUserDao;
import com.eatme.web.security.authentication.domain.entity.SecurityUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("phoneCodeUserDetailsServiceImpl")
@Transactional
public class PhoneCodeSecurityUserServiceImpl  {
    private static final Logger LOG = LoggerFactory.getLogger(PhoneCodeSecurityUserServiceImpl.class);

    private final SecurityUserDao securityUserDao;

    public PhoneCodeSecurityUserServiceImpl(SecurityUserDao securityUserDao) {
        this.securityUserDao = securityUserDao;
    }

    public SecurityUser findByPhone(String phone) {

        SecurityUser user = securityUserDao.findSecurityUserByList_Identifier(phone)
                // 抛UsernameNotFoundException异常
                .orElseThrow(() -> new UsernameNotFoundException("未找到手机号为"+phone+"的用户"));
        return user;
    }

}
